//
// Ishtar C++ Utility Library
//
// Task Facility - Periodic Timer Header
//

#ifndef __ISHTAR_TASK_PERIODIC_TIMER_H
#define __ISHTAR_TASK_PERIODIC_TIMER_H

#include <Ishtar/Ishtar.h>

#if defined( ISHTAR_COMPILER_HAS_PRAGMA_ONCE )
#pragma once
#endif

#include <Ishtar/InterlockedPointer.h>
#include <Ishtar/ReferenceCounted.h>
#include <Ishtar/Task/TaskFwd.h>
#include <Ishtar/Task/WorkExecutor.h>


namespace Ishtar
{

namespace Task
{

///////////////////////////////////////////////////////////////////////////////
//
// Periodic Timer
//

class PeriodicTimerImpl;

class PeriodicTimer
{
public:
    PeriodicTimer();
    
    PeriodicTimer(
        const std::string& name, const WorkFunction& workFunc, Uint dueTime, Uint period,
        WorkExecutor& executor
    );
    
    operator Bool() const { return this->IsAlive(); }

    Bool IsAlive() const;

    Bool Stop();
    

private:
    InterlockedIntrusivePtr< PeriodicTimerImpl > m_impl;
};

ISHTAR_REFERENCE_COUNTED_DECLARE( PeriodicTimerImpl )


///////////////////////////////////////////////////////////////////////////////

} // namespace Task

} // namespace Ishtar

#endif // __ISHTAR_TASK_PERIODIC_TIMER_H
